﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class DbEnProductsDal
	{
		public DbEnProductsDal()
		{
		}
 		#region Insert
 		public static int Insert(DbEnProducts dbEnProducts)
		{	
			string sql = @"Insert Into DbEnProducts (
					PCode,
					PEnName,
					PEnKeywords,
					PEnDescription,
					PEnNote,
					PEnShortInstr,
					PEnAddTime
				) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')";
			sql = string.Format(sql,
					SqlHelper.String(dbEnProducts.PCode),
					SqlHelper.String(dbEnProducts.PEnName),
					SqlHelper.String(dbEnProducts.PEnKeywords),
					SqlHelper.String(dbEnProducts.PEnDescription),
					dbEnProducts.PEnNote,
					SqlHelper.String(dbEnProducts.PEnShortInstr),
					dbEnProducts.PEnAddTime
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(DbEnProducts dbEnProducts)
		{	
			string sql = @"Update DbEnProducts set 

					PEnName= '{0}',
					PEnKeywords= '{1}',
					PEnDescription= '{2}',
					PEnNote= '{3}',
					PEnShortInstr= '{4}',
					PEnAddTime= '{5}'
				where

					PCode= '{6}'";
			sql = string.Format(sql,
					SqlHelper.String(dbEnProducts.PEnName),
					SqlHelper.String(dbEnProducts.PEnKeywords),
					SqlHelper.String(dbEnProducts.PEnDescription),
					dbEnProducts.PEnNote,
					SqlHelper.String(dbEnProducts.PEnShortInstr),
					dbEnProducts.PEnAddTime,
					dbEnProducts.PCode);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(System.String pCode)
		{
		
			string sql = @"Delete from DbEnProducts where 
					PCode= '{0}'";
			sql = string.Format(sql,
					pCode
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from DbEnProducts a "; 
			return SqlHelper.Select(sql);
		}
				
//        public static DbEnProducts Select(System.String pCode)
//        {
//            DbEnProducts dbEnProducts = null;
//            string sql = @"select a.* from DbEnProducts a  where
//					a.PCode= '{0}'
//";
//            sql = string.Format(sql,
//                    pCode
//);
//            DataSet ds = SqlHelper.Select(sql);
//            if(SqlHelper.HasRow(ds))
//                dbEnProducts = new DbEnProducts(ds.Tables[0].Rows[0]);					
//            return dbEnProducts;
//        }
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from DbEnProducts a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from dbEnProducts a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from DbEnProducts a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
